using HKB.Common;
using System;
using System.Data;
using System.Web;
namespace HKB.Web
{
	public class InterfaceBll
	{
		private Conn conn = null;
		public InterfaceBll()
		{
			this.conn = Text.GetComponent<Conn>("conn", HttpContext.Current.CurrentHandler);
		}
		public InterfaceBll(Conn _conn)
		{
			this.conn = _conn;
		}
		public DataTable GetInterfaceByInterfaceID(int InterfaceID)
		{
			IDbDataParameter dbDataParameter = this.conn.CreateParameter("@InterfaceID", DbType.Int32, InterfaceID);
			return this.conn.GetDataTable("Select * From [HL_Interface] Where ([InterfaceID] = @InterfaceID)", new IDbDataParameter[]
			{
				dbDataParameter
			});
		}
		public DataTable GetInterfaceNameID()
		{
			return this.conn.GetDataTable("Select InterfaceID, InterfaceName From [HL_Interface] Order By [InterfaceID] Desc");
		}
		public DataTable GetInterfaceName()
		{
			return this.conn.GetDataTable("Select InterfaceName From [HL_Interface] Order By [InterfaceID] Desc");
		}
		public DataTable GetInterfaces()
		{
			return this.conn.GetDataTable("Select * From [HL_Interface] Order By [InterfaceID] Desc");
		}
		public DataTable GetInterfaceActive(string type, string action)
		{
			string sql;
			if (type == "admin")
			{
				if (action == "login")
				{
					sql = "Select * From [HL_Interface] Where EnableAdminInterface=1 and LoginClose=0 Order By [InterfaceID] Desc";
				}
				else
				{
					if (action == "reg")
					{
						sql = "Select * From [HL_Interface] Where EnableAdminInterface=1 and RegClose=0 Order By [InterfaceID] Desc";
					}
					else
					{
						sql = "Select * From [HL_Interface] Where EnableAdminInterface=1 Order By [InterfaceID] Desc";
					}
				}
			}
			else
			{
				if (action == "login")
				{
					sql = "Select * From [HL_Interface] Where EnableFrontInterface=1 and LoginClose=0 Order By [InterfaceID] Desc";
				}
				else
				{
					if (action == "reg")
					{
						sql = "Select * From [HL_Interface] Where EnableFrontInterface=1 and RegClose=0 Order By [InterfaceID] Desc";
					}
					else
					{
						sql = "Select * From [HL_Interface] Where EnableFrontInterface=1 Order By [InterfaceID] Desc";
					}
				}
			}
			return this.conn.GetDataTable(sql);
		}
		public bool AddInterface(int EnableAdminInterface, int EnableFrontInterface, int AdminLoginOpenType, string AdminLoginPassword, string AdminLoginUrl, string InterfaceAdminUrl, string InterfaceFrontUrl, string InterfaceName, int InterfaceType, string CodePage, int LoginClose, int RegClose, DateTime UpdateTime, string Version, int CrossDomain, string UserCenterUrl)
		{
			if (UserCenterUrl == null)
			{
				UserCenterUrl = "";
			}
			string commandText = "INSERT INTO [HL_Interface] ([InterfaceName], [InterfaceFrontUrl], [InterfaceAdminUrl], [EnableFrontInterface], [EnableAdminInterface], [RegClose], [LoginClose], [InterfaceType], [Version], [AdminLoginUrl], [AdminLoginOpenType], [AdminLoginPassword], [UpdateTime], [CrossDomain], [UserCenterUrl], [CodePage]) VALUES (@InterfaceName, @InterfaceFrontUrl, @InterfaceAdminUrl, @EnableFrontInterface, @EnableAdminInterface, @RegClose, @LoginClose, @InterfaceType, @Version, @AdminLoginUrl, @AdminLoginOpenType, @AdminLoginPassword, @UpdateTime, @CrossDomain, @UserCenterUrl, @CodePage)";
			IDbDataParameter[] parameters = new IDbDataParameter[]
			{
				this.conn.CreateParameter("@InterfaceName", DbType.String, InterfaceName),
				this.conn.CreateParameter("@InterfaceFrontUrl", DbType.String, InterfaceFrontUrl),
				this.conn.CreateParameter("@InterfaceAdminUrl", DbType.String, InterfaceAdminUrl),
				this.conn.CreateParameter("@EnableFrontInterface", DbType.Int32, EnableFrontInterface),
				this.conn.CreateParameter("@EnableAdminInterface", DbType.Int32, EnableAdminInterface),
				this.conn.CreateParameter("@RegClose", DbType.Int32, RegClose),
				this.conn.CreateParameter("@LoginClose", DbType.Int32, LoginClose),
				this.conn.CreateParameter("@InterfaceType", DbType.Int32, InterfaceType),
				this.conn.CreateParameter("@Version", DbType.String, Version),
				this.conn.CreateParameter("@AdminLoginUrl", DbType.String, AdminLoginUrl),
				this.conn.CreateParameter("@AdminLoginOpenType", DbType.Int32, AdminLoginOpenType),
				this.conn.CreateParameter("@AdminLoginPassword", DbType.String, AdminLoginPassword),
				this.conn.CreateParameter("@UpdateTime", DbType.DateTime, UpdateTime),
				this.conn.CreateParameter("@CrossDomain", DbType.Int32, CrossDomain),
				this.conn.CreateParameter("@UserCenterUrl", DbType.String, UserCenterUrl),
				this.conn.CreateParameter("@CodePage", DbType.String, CodePage)
			};
			int num = this.conn.Execute(commandText, parameters);
			return num == 1;
		}
		public bool UpdateInterface(int InterfaceID, int EnableAdminInterface, int EnableFrontInterface, int AdminLoginOpenType, string AdminLoginPassword, string AdminLoginUrl, string InterfaceAdminUrl, string InterfaceFrontUrl, string InterfaceName, int InterfaceType, string CodePage, int LoginClose, int RegClose, DateTime UpdateTime, string Version, int CrossDomain, string UserCenterUrl)
		{
			if (UserCenterUrl == null)
			{
				UserCenterUrl = "";
			}
			string commandText = "UPDATE [HL_Interface] SET [InterfaceName] = @InterfaceName, [InterfaceFrontUrl] = @InterfaceFrontUrl, [InterfaceAdminUrl] = @InterfaceAdminUrl, [EnableFrontInterface] = @EnableFrontInterface, [EnableAdminInterface] = @EnableAdminInterface, [RegClose] = @RegClose, [LoginClose] = @LoginClose, [InterfaceType] = @InterfaceType, [Version] = @Version, [AdminLoginUrl] = @AdminLoginUrl, [AdminLoginOpenType] = @AdminLoginOpenType, [AdminLoginPassword] = @AdminLoginPassword, [UpdateTime] = @UpdateTime, [CrossDomain] = @CrossDomain, [UserCenterUrl] = @UserCenterUrl, [CodePage] = @CodePage WHERE (([InterfaceID] = @Original_InterfaceID))";
			IDbDataParameter[] parameters = new IDbDataParameter[]
			{
				this.conn.CreateParameter("@InterfaceName", DbType.String, InterfaceName),
				this.conn.CreateParameter("@InterfaceFrontUrl", DbType.String, InterfaceFrontUrl),
				this.conn.CreateParameter("@InterfaceAdminUrl", DbType.String, InterfaceAdminUrl),
				this.conn.CreateParameter("@EnableFrontInterface", DbType.Int32, EnableFrontInterface),
				this.conn.CreateParameter("@EnableAdminInterface", DbType.Int32, EnableAdminInterface),
				this.conn.CreateParameter("@RegClose", DbType.Int32, RegClose),
				this.conn.CreateParameter("@LoginClose", DbType.Int32, LoginClose),
				this.conn.CreateParameter("@InterfaceType", DbType.Int32, InterfaceType),
				this.conn.CreateParameter("@Version", DbType.String, Version),
				this.conn.CreateParameter("@AdminLoginUrl", DbType.String, AdminLoginUrl),
				this.conn.CreateParameter("@AdminLoginOpenType", DbType.Int32, AdminLoginOpenType),
				this.conn.CreateParameter("@AdminLoginPassword", DbType.String, AdminLoginPassword),
				this.conn.CreateParameter("@UpdateTime", DbType.DateTime, UpdateTime),
				this.conn.CreateParameter("@CrossDomain", DbType.Int32, CrossDomain),
				this.conn.CreateParameter("@UserCenterUrl", DbType.String, UserCenterUrl),
				this.conn.CreateParameter("@CodePage", DbType.String, CodePage),
				this.conn.CreateParameter("@Original_InterfaceID", DbType.String, InterfaceID)
			};
			int num = this.conn.Execute(commandText, parameters);
			return num == 1;
		}
		public bool DelInterface(int InterfaceID)
		{
			int num = this.conn.Execute("Delete From [HL_Interface] Where [InterfaceID]=" + InterfaceID);
			return num == 1;
		}
	}
}
